﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class Job_Details : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request.QueryString["postid"] != null)
            {
                string postid = Convert.ToString(Request.QueryString["postid"]);
                if (postid != "")
                {
                    postid = clsEncryptionDecryption.DecryptQueryString(postid);
                    hfJobPostId.Value = postid;
                }
            }
            if (Request.QueryString["companyname"] != null)
            {
                string companyname = Convert.ToString(Request.QueryString["companyname"]);
                if (companyname != "")
                {
                    companyname = clsEncryptionDecryption.DecryptQueryString(companyname);
                    lblCompanyName.Text = companyname;
                }
            }
            if (Request.QueryString["companydetails"] != null)
            {
                string companydetails = Convert.ToString(Request.QueryString["companydetails"]);
                if (companydetails != "")
                {
                    companydetails = clsEncryptionDecryption.DecryptQueryString(companydetails);
                    lblCompanyDescription.Text = companydetails;
                }
            }
            if (Request.QueryString["jobtitle"] != null)
            {
                string jobtitle = Convert.ToString(Request.QueryString["jobtitle"]);
                if (jobtitle != "")
                {
                    jobtitle = clsEncryptionDecryption.DecryptQueryString(jobtitle);
                    lblJobTitle.Text = jobtitle;
                }
            }
            if (Request.QueryString["jobdesc"] != null)
            {
                string jobdesc = Convert.ToString(Request.QueryString["jobdesc"]);
                if (jobdesc != "")
                {
                    jobdesc = clsEncryptionDecryption.DecryptQueryString(jobdesc);
                    lblJobDescription.Text = jobdesc;
                }
            }
            if (Request.QueryString["skillsreq"] != null)
            {
                string skillsreq = Convert.ToString(Request.QueryString["skillsreq"]);
                if (skillsreq != "")
                {
                    skillsreq = clsEncryptionDecryption.DecryptQueryString(skillsreq);
                    lblSkillsrequired.Text = skillsreq;
                }
            }
            if (Request.QueryString["joblocid"] != null)
            {
                string joblocid = Convert.ToString(Request.QueryString["joblocid"]);
                if (joblocid != "")
                {
                    joblocid = clsEncryptionDecryption.DecryptQueryString(joblocid);
                    int Job_locationId = Convert.ToInt32(joblocid);
                    clsCity objclsCity = new clsCity();
                    IN_TB_CITY objIN_TB_CITY = new IN_TB_CITY();
                    objIN_TB_CITY = objclsCity.GetCityById(Job_locationId);
                    if (objIN_TB_CITY != null)
                        lblJobLocation.Text = objIN_TB_CITY.CITY;
                }

            }
            if (Request.QueryString["expreq"] != null)
            {
                string expreq = Convert.ToString(Request.QueryString["expreq"]);
                if (expreq != "")
                {
                    expreq = clsEncryptionDecryption.DecryptQueryString(expreq);
                    lblExperienceRequired.Text = expreq;
                }
            }
            if (Request.QueryString["qualificationreq"] != null)
            {
                string qualificationreq = Convert.ToString(Request.QueryString["qualificationreq"]);
                if (qualificationreq != "")
                {
                    qualificationreq = clsEncryptionDecryption.DecryptQueryString(qualificationreq);
                    lblQualificationRequired.Text = qualificationreq;
                }
            }
            if (Request.QueryString["salaryoffered"] != null)
            {
                string salaryoffered = Convert.ToString(Request.QueryString["salaryoffered"]);
                if (salaryoffered != "")
                {
                    salaryoffered = clsEncryptionDecryption.DecryptQueryString(salaryoffered);
                    lblSalaryOfferd.Text = salaryoffered;
                }
            }
            if (Request.QueryString["functionalareaid"] != null)
            {
                string functionalareaid = Convert.ToString(Request.QueryString["functionalareaid"]);
                if (functionalareaid != "")
                {
                    functionalareaid = clsEncryptionDecryption.DecryptQueryString(functionalareaid);
                    int Functional_AreaId = Convert.ToInt32(functionalareaid);
                    clsFunctionalAreaDAL objclsFunctionalAreaDAL = new clsFunctionalAreaDAL();
                    IN_TB_FUNCTIONAL_AREA objIN_TB_FUNCTIONAL_AREA = new IN_TB_FUNCTIONAL_AREA();
                    objIN_TB_FUNCTIONAL_AREA = objclsFunctionalAreaDAL.GetAllFunctionalAreaById(Functional_AreaId);
                    if (objIN_TB_FUNCTIONAL_AREA != null)
                        lblFunctionalArea.Text = objIN_TB_FUNCTIONAL_AREA.FUNCTIONAL_AREA;
                }
            }
            if (Request.QueryString["jobpostedon"] != null)
            {
                string jobpostedon = Convert.ToString(Request.QueryString["jobpostedon"]);
                if (jobpostedon != "")
                {
                    jobpostedon = clsEncryptionDecryption.DecryptQueryString(jobpostedon);
                    DateTime dt = Convert.ToDateTime(jobpostedon);
                    lblJobPostedOn.Text = dt.ToString("dd-MMM-yyyy");
                }
            }

            if (Session["UserId"] != null && hfJobPostId.Value != "")
            {
                clsJobsAppliedDAL objclsJobsAppliedDAL = new clsJobsAppliedDAL();
                bool Result = objclsJobsAppliedDAL.IsJobApplied(Convert.ToInt32(Session["UserId"]), Convert.ToInt32(hfJobPostId.Value));
                if (Result == true)
                {
                    btnApplyJob.Enabled = false;
                    btnApplyJob.Text = "Already Applied";
                    trJobstatus.Visible = true;
                    trCurrentstatus.Visible = true;
                    trComment.Visible = true;
                }
                else
                {
                    btnApplyJob.Enabled = true;
                    btnApplyJob.Text = "Apply";
                    trJobstatus.Visible = false;
                    trCurrentstatus.Visible = false;
                    trComment.Visible = false;
                }
                IN_TB_JOB_APPLIED objIN_TB_JOB_APPLIED = new IN_TB_JOB_APPLIED();
                objIN_TB_JOB_APPLIED = objclsJobsAppliedDAL.GetJobStatusByUser(Convert.ToInt32(Session["UserId"]), Convert.ToInt32(hfJobPostId.Value));
                if (objIN_TB_JOB_APPLIED != null)
                {
                    if (objIN_TB_JOB_APPLIED.STATUS == 1)
                        lblCurrentStatus.Text = "Not Seen";
                    if (objIN_TB_JOB_APPLIED.STATUS == 2)
                        lblCurrentStatus.Text = "Seen";
                    if (objIN_TB_JOB_APPLIED.STATUS == 3)
                        lblCurrentStatus.Text = "On Hold";
                    if (objIN_TB_JOB_APPLIED.STATUS == 4)
                        lblCurrentStatus.Text = "Selected";
                    if (objIN_TB_JOB_APPLIED.STATUS == 5)
                        lblCurrentStatus.Text = "Rejected";

                    lblEmployerComment.Text = Convert.ToString(objIN_TB_JOB_APPLIED.EMPLOYER_COMMENT);
                }
            }
        }
    }
    protected void btnApplyJob_Click(object sender, EventArgs e)
    {
        try
        {
            if (Session["UserId"] != null && hfJobPostId.Value != "")
            {
                clsJobsAppliedDAL objclsJobsAppliedDAL = new clsJobsAppliedDAL();
                IN_TB_JOB_APPLIED objIN_TB_JOB_APPLIEDNEW = new IN_TB_JOB_APPLIED();
                objIN_TB_JOB_APPLIEDNEW.USER_ID = Convert.ToInt32(Session["UserId"].ToString());
                objIN_TB_JOB_APPLIEDNEW.JOB_ID = Convert.ToInt32(hfJobPostId.Value.ToString());
                objIN_TB_JOB_APPLIEDNEW.STATUS = 1;
                objIN_TB_JOB_APPLIEDNEW.APPLIED_ON = DateTime.Now;
                int JobAppliedId = objclsJobsAppliedDAL.SaveJobsApplied(objIN_TB_JOB_APPLIEDNEW);
            }
        }
        catch (Exception)
        {
            throw;
        }
    }
}
